New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mpath

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mpath

{G,S}et object values using MongoDB-like path notation

0.6.0
Source
npm
Version published
Weekly downloads
2.8M
2.41%
Maintainers
2
Weekly downloads
 
Created

What is mpath?

The mpath npm package is a utility for getting and setting values of nested properties in JavaScript objects using dot notation or array paths. It is particularly useful for manipulating deeply nested objects without having to write complex and repetitive code.

What are mpath's main functionalities?

Get Value

This feature allows you to retrieve the value of a nested property within an object using a dot notation path.

const mpath = require('mpath');
const obj = { a: { b: { c: 42 } } };
const value = mpath.get('a.b.c', obj);
console.log(value); // 42

Set Value

This feature allows you to set the value of a nested property within an object using a dot notation path.

const mpath = require('mpath');
const obj = { a: { b: { c: 42 } } };
mpath.set('a.b.c', 100, obj);
console.log(obj.a.b.c); // 100

Unset Value

This feature allows you to unset (delete) a nested property within an object using a dot notation path.

const mpath = require('mpath');
const obj = { a: { b: { c: 42 } } };
mpath.unset('a.b.c', obj);
console.log(obj.a.b.c); // undefined

Has Value

This feature allows you to check if a nested property exists within an object using a dot notation path.

const mpath = require('mpath');
const obj = { a: { b: { c: 42 } } };
const hasValue = mpath.has('a.b.c', obj);
console.log(hasValue); // true

Other packages similar to mpath

Keywords

mongodb

FAQs

Package last updated on 01 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts